Repository navigation
fix: refuse inputs that could delete, wipe or leak, and bound search paging - #147
Merged
Merged
Conversation
An empty name built a path with an empty segment, and erchef's router drops an empty trailing one: Items(bag).Delete(ctx, "") sent DELETE /data/<bag>/, which routes to chef_wm_named_data and deletes the whole bag. A "." or ".." name names a different object to any proxy that normalizes the path. doRaw now refuses a path (before any query) with an empty, "." or ".." segment before anything is sent, for every typed service and Do. A 2xx GET with an empty or null body decoded as an empty object. Groups.AddMembers and ACLs.Grant then wrote that back with only the new member, dropping every existing one, and Users.SetPassword panicked on the nil map. Every Chef GET answers with a JSON document, so do now reports an empty or null GET body as an error. Signed-off-by: Tim Smith <tsmith84@proton.me>
…ts out of errors Search: a server whose total promises rows it never returns kept the iterator paging until the context ended (1e9 requests for total=1e12), and WithRows(MaxInt) overflowed the next start into a negative number. Paging still advances by the page size asked for, so one empty page of deleted objects does not end it, but ten empty pages in a row are now an error (the results are incomplete), and the offset cannot overflow. DownloadFiles: two manifest entries landing on one file (recipes/./x.rb beside recipes/x.rb, or default.rb beside DEFAULT.rb on the case-insensitive filesystems macOS and Windows use by default) raced two writers onto it and one silently won. They are now refused before anything is written. Errors: an S3 or bookshelf error body can echo the request's credentials (SignatureDoesNotMatch includes the canonical request, access key and signature); a transfer error now keeps only the XML Code and Message. A raw error body that is not a Chef error document is capped at 512 bytes. A transfer body a handler left unread is drained so the connection is reused. Decrypted data bag values with trailing data after the JSON object are refused rather than read as the first value. Signed-off-by: Tim Smith <tsmith84@proton.me>
On Linux default.rb and DEFAULT.rb are two files and download normally, so the test fetched them and failed there. Signed-off-by: Tim Smith <tsmith84@proton.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes for malformed input from the second pre-1.0 review.
Empty or dot path segments. An empty name built a path with an empty segment, and erchef's router drops an empty trailing segment (
dispatch.confroutes[..., "data", data_bag_name]tochef_wm_named_data). SoItems(bag).Delete(ctx, "")sentDELETE /data/<bag>/and deleted the whole bag. A.or..name names a different object to any proxy that normalizes paths.doRawnow refuses a path with an empty,.or..segment before sending. This covers every typed service andDo; queries are exempt.Empty GET bodies. A 200 GET with an empty or
nullbody decoded as an empty object:Groups.AddMembersandACLs.Grantthen PUT back only the new member, dropping every existing one, and returnednil.Users.SetPasswordpanicked on the nil map.Every Chef GET returns a JSON document, so an empty one is now an error.
Search paging. A
totalthat promises rows the server never sends kept the iterator paging until the context ended, andWithRows(math.MaxInt)overflowed the next start into a negative number.Download collisions. Two manifest entries that land on one file raced two writers onto it, and one silently won. Examples:
recipes/./x.rbbesiderecipes/x.rb, ordefault.rbbesideDEFAULT.rbon macOS/Windows default filesystems. Both cases are now refused before anything is written.Secrets in errors. An S3
SignatureDoesNotMatchbody echoes the canonical request, the access key and the signature. Transfer errors now keep only the XMLCodeandMessage. A non-Chef error body (such as a proxy HTML page) is capped at 512 bytes. A transfer body left unread is drained so the connection is reused.Decrypted values with trailing data after the JSON object are refused.
Test plan
defensive_test.go, one test per case. Before the fix, the empty-body test showed both destructive PUTs and theSetPasswordpanic; now no write reaches the server.go test ./... -race -count=2; new code at 100% coverage, package coverage 98.3%cd integration && go test ./...: the path guard on every real request